<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>课表管理系统 - 设置</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        /* 全局样式重置 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }

        /* CSS变量定义-主题颜色 */
        :root {
            --primary: #4361ee;
            --secondary: #3f37c9;
            --light: #f8f9fa;
            --dark: #212529;
            --border: #e0e0e0;
            --text: #333;
            --card-bg: white;
            --control-bg: #f0f4f8;
            --font-size-base: 16px;
        }

        /* 深色模式变量 */
        .dark-mode {
            --primary: #7988f5;
            --secondary: #6a62e0;
            --light: #1e293b;
            --dark: #f8fafc;
            --border: #334155;
            --text: #f1f5f9;
            --card-bg: #334155;
            --control-bg: #1e293b;
        }

        body {
            background-color: var(--light);
            color: var(--text);
            line-height: 1.6;
            min-height: 100vh;
            font-size: var(--font-size-base);
            transition: all 0.3s ease;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
            background-color: var(--card-bg);
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
            overflow: hidden;
            margin-top: 30px;
            margin-bottom: 30px;
        }

        header {
            background: linear-gradient(to right, var(--primary), var(--secondary));
            color: white;
            padding: 20px 30px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .logo h1 {
            font-size: 1.8rem;
            font-weight: 600;
        }

        .logo i {
            font-size: 2rem;
        }

        .settings-content {
            padding: 30px;
        }

        .settings-section {
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 1px solid var(--border);
        }

        .settings-section:last-child {
            border-bottom: none;
            margin-bottom: 0;
        }

        .section-title {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 20px;
            color: var(--secondary);
        }

        .section-title i {
            font-size: 1.5rem;
        }

        .section-title h2 {
            font-size: 1.5rem;
            font-weight: 600;
        }

        .setting-item {
            margin-bottom: 25px;
        }

        .setting-label {
            display: block;
            margin-bottom: 10px;
            font-weight: 500;
            font-size: 1.1rem;
        }

        .setting-description {
            color: #64748b;
            margin-bottom: 15px;
            font-size: 0.9rem;
        }

        .font-size-controls {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .font-size-display {
            min-width: 60px;
            text-align: center;
            padding: 8px 12px;
            background-color: var(--control-bg);
            border-radius: 8px;
            font-weight: 500;
        }

        .slider-container {
            flex: 1;
        }

        .font-size-slider {
            width: 100%;
            height: 6px;
            -webkit-appearance: none;
            appearance: none;
            background: #e2e8f0;
            border-radius: 3px;
            outline: none;
        }

        .font-size-slider::-webkit-slider-thumb {
            -webkit-appearance: none;
            appearance: none;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background: var(--primary);
            cursor: pointer;
            transition: all 0.2s ease;
        }

        .font-size-slider::-webkit-slider-thumb:hover {
            transform: scale(1.2);
        }

        /* 7.7 */
        .font-size-example .size-xs { font-size: 12px !important; }
        .font-size-example .size-sm { font-size: 14px !important; }
        .font-size-example .size-md { font-size: 16px !important; }
        .font-size-example .size-lg { font-size: 18px !important; }
        .font-size-example .size-xl { font-size: 20px !important; }
        /* 7.7 */

        .theme-switch {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .switch {
            position: relative;
            display: inline-block;
            width: 60px;
            height: 34px;
        }

        .switch input {
            opacity: 0;
            width: 0;
            height: 0;
        }

        .slider {
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #ccc;
            transition: .4s;
            border-radius: 34px;
        }

        .slider:before {
            position: absolute;
            content: "";
            height: 26px;
            width: 26px;
            left: 4px;
            bottom: 4px;
            background-color: white;
            transition: .4s;
            border-radius: 50%;
        }

        input:checked + .slider {
            background-color: var(--primary);
        }

        input:checked + .slider:before {
            transform: translateX(26px);
        }

        .theme-option {
            display: flex;
            align-items: center;
            gap: 8px;
            font-weight: 500;
        }

        .button-group {
            display: flex;
            justify-content: flex-end;
            gap: 15px;
            margin-top: 20px;
        }

        .btn {
            padding: 12px 25px;
            border-radius: 8px;
            border: none;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 1rem;
        }

        .btn-cancel {
            background-color: var(--control-bg);
            color: var(--text);
            border: 1px solid var(--border);
        }

        .btn-save {
            background: linear-gradient(to right, var(--primary), var(--secondary));
            color: white;
        }

        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .btn-cancel:hover {
            background-color: #e2e8f0;
        }

        .preview-text {
            padding: 15px;
            background-color: var(--control-bg);
            border-radius: 8px;
            margin-top: 10px;
            border: 1px solid var(--border);
        }

        .font-sizes {
            display: flex;
            justify-content: space-between;
            margin-top: 10px;
        }

        .font-size-example {
            text-align: center;
        }

        .size-xs {
            font-size: calc(var(--font-size-base) * 0.8);
        }

        .size-sm {
            font-size: calc(var(--font-size-base) * 0.9);
        }

        .size-md {
            font-size: var(--font-size-base);
            font-weight: bold;
        }

        .size-lg {
            font-size: calc(var(--font-size-base) * 1.1);
        }

        .size-xl {
            font-size: calc(var(--font-size-base) * 1.2);
        }

        footer {
            text-align: center;
            padding: 20px;
            color: #64748b;
            font-size: 0.9rem;
            border-top: 1px solid var(--border);
            margin-top: 20px;
        }

        .toast {
            position: fixed;
            bottom: 30px;
            left: 50%;
            transform: translateX(-50%) translateY(100px);
            background-color: rgba(0, 0, 0, 0.7);
            color: white;
            padding: 12px 24px;
            border-radius: 8px;
            font-weight: 500;
            z-index: 1000;
            opacity: 0;
            transition: all 0.3s ease;
        }

        .toast.show {
            transform: translateX(-50%) translateY(0);
            opacity: 1;
        }
        /* 7.7 */
        /* 背景图片上传样式 */
        .background-upload {
            margin-top: 15px;
        }
        /* 上传按钮样式 */
        .upload-btn {
            display: inline-flex;
            margin-bottom: 15px;
        }
        /* 预览容器样式 */
        .preview-container {
            border: 1px dashed var(--border);
            border-radius: 8px;
            padding: 20px;
            text-align: center;
            min-height: 150px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
        }

        .bg-preview {
            max-width: 100%;
            max-height: 200px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        /* 7.7 */
        /* .bg-preview img {
            max-width: 100%;
            max-height: 100%;
            object-fit: cover;
        } */
        /* 7.7 */

        #noBgText {
            color: var(--text);
            margin: 0;
        }

        /* 深色模式适配 */
        body.dark-mode .preview-container {
            border-color: #4b5563;
        }

        body.dark-mode #noBgText {
            color: #a0aec0;
        }
        /* 彻底隐藏原生文件选择按钮 */
        #bgImageUpload.hidden {
            display: none !important; /* 强制隐藏 */
            visibility: hidden;
            width: 0;
            height: 0;
            opacity: 0;
        }
        /* 7.7 */
    </style>
</head>
<body>
    <div class="container">
        <header>
            <div class="logo">
                <i class="fas fa-cog"></i>
                <h1>系统设置</h1>
            </div>
            <button class="btn btn-cancel" onclick="window.location.href='courses_view(1).html'">
                <i class="fas fa-arrow-left"></i> 返回
            </button>
        </header>

        <div class="settings-content">
            <div class="settings-section">
                <div class="section-title">
                    <i class="fas fa-text-height"></i>
                    <h2>字体设置</h2>
                </div>

                <div class="setting-item">
                    <label class="setting-label">字体大小</label>
                    <p class="setting-description">调整系统界面的字体大小，设置后将应用到整个课表系统</p>
                    
                    <div class="font-size-controls">
                        <div class="slider-container">
                            <input type="range" min="14" max="20" value="16" class="font-size-slider" id="fontSizeSlider">
                        </div>
                        <div class="font-size-display" id="fontSizeValue">16px</div>
                    </div>

                    <div class="preview-text">
                        <p>预览文本：这是一段示例文本，展示当前字体大小效果</p>
                        <div class="font-sizes">
                            <div class="font-size-example">
                                <div class="size-xs">小</div>
                            </div>
                            <div class="font-size-example">
                                <div class="size-sm">较小</div>
                            </div>
                            <div class="font-size-example">
                                <div class="size-md">标准</div>
                            </div>
                            <div class="font-size-example">
                                <div class="size-lg">较大</div>
                            </div>
                            <div class="font-size-example">
                                <div class="size-xl">大</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="settings-section">
                <div class="section-title">
                    <i class="fas fa-adjust"></i>
                    <h2>主题设置</h2>
                </div>

                <div class="setting-item">
                    <label class="setting-label">主题模式</label>
                    <p class="setting-description">选择深色或浅色模式，设置将应用到整个课表系统</p>
                    
                    <div class="theme-switch">
                        <label class="theme-option">
                            <i class="fas fa-sun"></i>
                            <span>浅色模式</span>
                        </label>
                        
                        <label class="switch">
                            <input type="checkbox" id="themeToggle">
                            <span class="slider"></span>
                        </label>
                        
                        <label class="theme-option">
                            <i class="fas fa-moon"></i>
                            <span>深色模式</span>
                        </label>
                    </div>
                </div>
            </div>

            <!-- 7.7 -->
            <div class="settings-section">
                <div class="section-title">
                    <i class="fas fa-image"></i>
                    <h2>背景设置</h2>
                </div>

                <div class="setting-item">
                    <label class="setting-label">课表背景图片</label>
                    <p class="setting-description">上传图片作为课表页面的背景，支持JPG、PNG格式</p>
        
                    <!-- 图片上传区域 -->
                    <div class="background-upload">
                        <input type="file" id="bgImageUpload" accept="image/jpeg, image/png" class="hidden">
                        <label for="bgImageUpload" class="btn btn-cancel upload-btn">
                            <i class="fas fa-upload"></i> 选择图片
                        </label>
            
                        <!-- 预览区域 -->
                        <div class="preview-container" id="bgPreviewContainer">
                            <img id="bgPreview" class="bg-preview" src="" alt="背景预览" style="display: none;">
                            <p id="noBgText">未设置背景图片</p>
                        </div>
            
                        <!-- 清除按钮 -->
                        <button id="clearBgBtn" class="btn btn-cancel" style="margin-top: 10px; display: none;">
                            <i class="fas fa-trash"></i> 清除背景
                        </button>
                    </div>
                </div>
            </div>
            <!-- 7.7 -->

            <div class="button-group">
                <button class="btn btn-cancel" id="resetBtn">
                    <i class="fas fa-undo"></i> 恢复默认
                </button>
                <button class="btn btn-save" id="saveBtn">
                    <i class="fas fa-save"></i> 保存设置
                </button>
            </div>
        </div>

        <footer>
            <p>课表管理系统 &copy; 2025 | 设置模块</p>
        </footer>
    </div>

     <div class="toast" id="toast"></div>

    <script>
        // DOM元素
        const fontSizeSlider = document.getElementById('fontSizeSlider');
        const fontSizeValue = document.getElementById('fontSizeValue');
        const themeToggle = document.getElementById('themeToggle');
        const saveBtn = document.getElementById('saveBtn');
        const resetBtn = document.getElementById('resetBtn');
        const toast = document.getElementById('toast');
        const htmlElement = document.documentElement;


        // 7.7
        // 元素获取
        const bgImageUpload = document.getElementById('bgImageUpload');
        const bgPreview = document.getElementById('bgPreview');
        const bgPreviewContainer = document.getElementById('bgPreviewContainer');
        const noBgText = document.getElementById('noBgText');
        const clearBgBtn = document.getElementById('clearBgBtn');

        // 页面加载时读取已保存的背景图片
        function loadBackgroundImage() {
            const savedBg = localStorage.getItem('scheduleBgImage');
            if (savedBg) {
                // 显示预览
                bgPreview.src = savedBg;
                bgPreview.style.display = 'block';
                noBgText.style.display = 'none';
                clearBgBtn.style.display = 'inline-flex';
            }
        }

        // 保存背景图片到本地存储
        function saveBackgroundImage(dataUrl) {
            localStorage.setItem('scheduleBgImage', dataUrl);
            showToast('背景图片已保存');
        }

        // 处理图片上传
        bgImageUpload.addEventListener('change', function(e) {
            const file = e.target.files[0];
            if (!file) return;

            // 检查文件类型
            if (!file.type.match('image/jpeg') && !file.type.match('image/png')) {
                showToast('请上传JPG或PNG格式的图片');
                return;
            }

            // 读取图片并显示预览
            const reader = new FileReader();
            reader.onload = function(event) {
                const dataUrl = event.target.result;
                bgPreview.src = dataUrl;
                bgPreview.style.display = 'block';
                noBgText.style.display = 'none';
                clearBgBtn.style.display = 'inline-flex';
                
                // 保存图片
                saveBackgroundImage(dataUrl);
            };
            reader.readAsDataURL(file);
        });

        // 清除背景图片
        clearBgBtn.addEventListener('click', function() {
            localStorage.removeItem('scheduleBgImage');
            bgPreview.src = '';
            bgPreview.style.display = 'none';
            noBgText.style.display = 'block';
            clearBgBtn.style.display = 'none';
            showToast('背景图片已清除');
        });

        
        // 7.7

        // 加载保存的设置
        function loadSettings() {
            const savedSettings = localStorage.getItem('scheduleSettings');
            if (savedSettings) {
                const settings = JSON.parse(savedSettings);
                
                // 应用字体大小设置
                fontSizeSlider.value = settings.fontSize;
                fontSizeValue.textContent = `${settings.fontSize}px`;
                document.documentElement.style.setProperty('--font-size-base', `${settings.fontSize}px`);
                
                // 应用主题设置
                if (settings.darkMode) {
                    document.body.classList.add('dark-mode');
                    themeToggle.checked = true;
                } else {
                    document.body.classList.remove('dark-mode');
                    themeToggle.checked = false;
                }
            }
        }

        // 保存设置
        function saveSettings() {
            const settings = {
                fontSize: parseInt(fontSizeSlider.value),
                darkMode: themeToggle.checked
            };
            
            localStorage.setItem('scheduleSettings', JSON.stringify(settings));
            showToast('设置已保存');
        }

        // 恢复默认设置
        function resetToDefault() {
            if (confirm('确定要恢复默认设置吗？')) {
                // 默认设置
                const defaultSettings = {
                    fontSize: 16,
                    darkMode: false
                };
                
                // 应用默认设置
                fontSizeSlider.value = defaultSettings.fontSize;
                fontSizeValue.textContent = `${defaultSettings.fontSize}px`;
                document.documentElement.style.setProperty('--font-size-base', `${defaultSettings.fontSize}px`);
                
                if (defaultSettings.darkMode) {
                    document.body.classList.add('dark-mode');
                    themeToggle.checked = true;
                } else {
                    document.body.classList.remove('dark-mode');
                    themeToggle.checked = false;
                }
                
                // 保存默认设置
                localStorage.setItem('scheduleSettings', JSON.stringify(defaultSettings));
                showToast('已恢复默认设置');
            }
        }

        // 显示提示消息
        function showToast(message) {
            toast.textContent = message;
            toast.classList.add('show');
            
            setTimeout(() => {
                toast.classList.remove('show');
            }, 2000);
        }

        // 事件监听
        fontSizeSlider.addEventListener('input', function() {
            const fontSize = this.value;
            fontSizeValue.textContent = `${fontSize}px`;
            document.documentElement.style.setProperty('--font-size-base', `${fontSize}px`);
        });

        themeToggle.addEventListener('change', function() {
            if (this.checked) {
                document.body.classList.add('dark-mode');
            } else {
                document.body.classList.remove('dark-mode');
            }
        });

        saveBtn.addEventListener('click', saveSettings);
        resetBtn.addEventListener('click', resetToDefault);
        // 7.7
        // 页面加载时应用保存的设置
        document.addEventListener('DOMContentLoaded', function() {
            loadSettings();       // 先加载字体和主题设置
            loadBackgroundImage(); // 再加载背景图片
        });
        // 7.7
    </script>
</body>

</html>